<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数调用</title>
</head>
<body>
    <script>
        (function () {
            document.write("我是自己调用自己的<br>")
        })()

        function myFunction(a,b) {
            return a+b
        }
        var x = myFunction(4,3)
        document.write(x+"<br>")
        document.write(myFunction(9,2).toString()+"<br>")

        var myObject = {
            firstName:"John",
            lastName:"Doe",
            fullName:function () {
                return this.firstName+"      "+this.lastName
            }
        }
        document.write(myObject.fullName()+"<br>")
        function myFunction(a,b) {
            return a*b
        }
        document.write( myFunction.call(myObject,10,2)+"<br>")
        document.write(myFunction.apply(myObject,[10,2])+"<br>")

        var a = 4
        function compareFunction() {
            var a = 2
            return a
        }
        var func = new  compareFunction()
        document.write(a+"     "+compareFunction()+"<br>")

        var add = (function () {
            var counter = 0
            return function () {
                return counter+=1
            }
        })()
        document.write(add()+"<br>")
        document.write(add()+"<br>")
        document.write(add()+"<br>")
        document.write(add()+"<br>")

        var floatNum = 0.2222222
        document.write(floatNum.toFixed(2)+"<br>")
    </script>
</body>
</html>